﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
using SES.CMS.DO;
using SES.CMS.BL;

namespace SES.CMS
{
    public partial class Article : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.QueryString["ID"] != null)
            {
                int id = int.Parse(Request.QueryString["ID"]);
                cmsArticleDO objCat = new cmsArticleDO();
                objCat.ArticleID = id;
                objCat = new cmsArticleBL().Select(objCat);

                cmsCategoryDO objCatnews = new cmsCategoryDO();
                objCatnews.CategoryID = objCat.CategoryID;
                objCatnews = new cmsCategoryBL().Select(objCatnews);


                Page.Title = objCat.Title + " - " + objCatnews.Title + " - Văn Phòng phẩm Mỹ Đình";
                lblTitle.Text = objCat.Title;
                lblInfo.Text = objCat.ArticleDetail;
                imgContent.ImageUrl = "/Media/" + objCat.ImageUrl;
                hplImg.NavigateUrl = "/Media/" + objCat.ImageUrl;
                hplImg.Attributes.Add("Title", objCat.Title);


                rptOther.DataSource = new DataView(new cmsArticleBL().SelectByCatNum(objCat.CategoryID, 10), "ArticleID<>" + objCat.ArticleID.ToString(), "", DataViewRowState.CurrentRows);
                rptOther.DataBind();
            }

            else if (Request.QueryString["IDPR"] != null)
            {
                string s = Request.QueryString["IDPR"].ToString();
                int id = int.Parse(Request.QueryString["IDPR"].ToString());
                DataTable dt = new DataTable();
                dt = new cmsArticleBL().SelectByCategoryID(id);
                if (dt.Rows.Count > 0)
                {
                    cmsCategoryDO objCatnews = new cmsCategoryDO();
                    objCatnews.CategoryID = id;
                    objCatnews = new cmsCategoryBL().Select(objCatnews);



                    Page.Title = dt.Rows[0].ItemArray[1].ToString() + " - " + objCatnews.Title + " - Văn Phòng phẩm Mỹ Đình";
                    lblTitle.Text = dt.Rows[0].ItemArray[1].ToString();
                    lblInfo.Text = dt.Rows[0].ItemArray[5].ToString();
                    imgContent.ImageUrl = "/Media/" + dt.Rows[0].ItemArray[3].ToString();
                    hplImg.NavigateUrl = "/Media/" + dt.Rows[0].ItemArray[3].ToString();
                    hplImg.Attributes.Add("Title", dt.Rows[0].ItemArray[1].ToString());


                    rptOther.DataSource = new DataView(new cmsArticleBL().SelectByCatNum(id, 10), "ArticleID<>" + dt.Rows[0].ItemArray[0].ToString(), "", DataViewRowState.CurrentRows);
                    rptOther.DataBind();
                }
            }
        }
        public string Change_AV(string ip_str_change)
        {
            return Ultility.Change_AV(ip_str_change);
        }
        public string CheckDate(string sDate)
        {
            //kiem tra ngay thang neu nho hon ngay hien tai (chu y parse sang datetime) 
            DateTime startDate = Convert.ToDateTime(sDate);
            DateTime now = DateTime.Now;
            TimeSpan elapsed = now.Subtract(startDate);
            double daysAgo = elapsed.TotalDays;
            if (daysAgo < 30)
            {
                //return "<span class=\"red\">" + sDate; 
                //return "<asp:Image ID=\"imgNew\" ImageUrl=\"~/images/New_icons_07.gif\" runat=\"server\" AlternateText=\"New\" />";
                return "<img src=\"/images/New_icons_07.gif\" AlternateText=\"New\" />";
            }
            else
            {
                return " ";
            }
        }
    }
}
